//
//  MyButton.m
//  JiFengDaRen
//
//  Created by guest on 16/1/20.
//  Copyright © 2016年 陈永发. All rights reserved.
//

#import "MyButton.h"

@implementation MyButton
-(instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        self.titleLabel.textAlignment = 1;
        [self addTarget:self action:@selector(jumpTo:) forControlEvents:UIControlEventTouchUpInside];
        [self setBackgroundImage:[UIImage imageNamed:@"loginHilight"] forState:UIControlStateHighlighted];
    }
    return self;
}
+(instancetype)buttonWithFrame:(CGRect)frame title:(NSString *)title image:(NSString *)image titleColor:(UIColor *)titleColor font:(CGFloat)font tag:(NSInteger)tag{
    MyButton *myBtn = [[MyButton alloc]initWithFrame:frame];
    
    [myBtn setTitleColor:titleColor forState:UIControlStateNormal];
    [myBtn setImage:[UIImage imageNamed:image]forState:UIControlStateNormal]
    ;
    [myBtn setTitle:title forState:UIControlStateNormal];
    myBtn.titleLabel.font = [UIFont systemFontOfSize:font];
    myBtn.tag = tag;
//    myBtn.layer.borderWidth = 1.0f;
//    myBtn.layer.borderColor = [UIColor grayColor].CGColor;
   
    return myBtn;
    
}
#pragma mark -- 九宫格按钮点击事件
-(void)jumpTo:(MyButton*)nineSquare{
    if (_myButtonDidTapAtIndexBlock != nil) {
        _myButtonDidTapAtIndexBlock(nineSquare.tag);
    }
}

-(CGRect)titleRectForContentRect:(CGRect)contentRect{
    return CGRectMake(0,contentRect.size.height - __I6Height(30),contentRect.size.width,__I6Height(15));
}
-(CGRect)imageRectForContentRect:(CGRect)contentRect{
    
    return CGRectMake((contentRect.size.width - __I6Width(35)) / 2.0,__I6Height(20),__I6Width(35),__I6Width(35));
}


@end
